package com.gomtel.smartdevice.ui.dialog;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.WatchBaseDialog;
import com.gomtel.smartdevice.bean.AboutDataBean;
import com.gomtel.smartdevice.moudle.event.CommonEvent;
import com.gomtel.smartdevice.moudle.event.EventCode;
import com.gomtel.smartdevice.moudle.rxtools.EventBusUtil;
import com.gomtel.smartdevice.utils.SystemUtil;
import com.gomtel.smartdevice.utils.ToastUtil;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;


/**
 * Created by Administrator on 2018/3/21.
 */

public class LoopDialog extends WatchBaseDialog implements View.OnClickListener {

    private Context context;
    private int status;
    @BindView(R.id.loop_view)
    LoopView loop_view;
    @BindView(R.id.btn_commit)
    Button btn_commit;
    @BindView(R.id.btn_cancle)
    Button btn_cancle;
    private ArrayList<String> arrayList = new ArrayList<>();

    protected LoopDialog(Context context, @StyleRes int themeResId, int status) {
        super(context, themeResId);
        this.context = context;
        this.status = status;
    }

    @Override
    protected int getLayout() {
        return R.layout.dialog_loop;
    }

    @Override
    protected void initClass() {

    }

    @Override
    protected void initData() {
        for (int i = 1; i < 12 * 60; i++) {
            arrayList.add(String.valueOf(i));
        }
    }

    @Override
    protected void initView() {
        loop_view.setItems(arrayList);
        loop_view.setInitPosition(status - 1);
        loop_view.setNotLoop();
    }

    @Override
    protected void initListener() {
        btn_commit.setOnClickListener(this);
        btn_cancle.setOnClickListener(this);
        loop_view.setListener(loopViewMListener);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_commit:
                EventBusUtil.sendEvent(new CommonEvent(EventCode.SELECT_LOOP, status));
                dismiss();
                break;
            case R.id.btn_cancle:
                dismiss();
                break;
        }

    }

    private final OnItemSelectedListener loopViewMListener = new OnItemSelectedListener() {
        @Override
        public void onItemSelected(int index) {
            status = Integer.valueOf(arrayList.get(index));
        }
    };


    @Override
    protected void onDismissListener() {
        super.onDismissListener();
    }


}
